
    //“查找列表”加载------------------------------------- -->
	//点击添加成员或者主管的按钮
    var department_id="";
    var temp = 0;
    $('.s_search_box').click(function(){ 
    	department_id=$('.fL_add').attr('department_id');
    	//alert(department_id);
    	if($(this).prop("id")=="s_search_leader"){
    		temp = 1;
    	}else{
    		temp =2;    		
    	}
    	$("#userList").empty();
    	//alert(temp);
    	sysuserList();
        $('.s_popup').hide();
        $('.issue').hide();
        $('.s_popups').show();
        $('.s_number_list').show();
    });
    //查询列表
    var startIndex = 0;
    var pageSize = 5;
    var currentPage = 1;
    var pageCount = 0;
    $(function(){
    	//sysuserList();
    });
	var leadID="";
    function sysuserList(){		
		console.log("department_id:::::"+department_id);
    	$.post(path+'/api/department/searchList', {    		
				"startIndex" : startIndex,
				"pagesize" : pageSize,				
				"keyWord" : $("#keyword").val(),
				"role":$("#s").text(),
				"department_id":department_id
		}, function(data) {
			if(temp == 1){
				if(data.leadInfo.sid!=null){
					leadID=data.leadInfo.sid;
				}				
				sysuserhtml_l(data.sysuserList);	
				page(data.totalCount);				
			}else if(temp== 2){
				//alert("进入222sys");
				sysuserhtml_m(data.sysuserList);	
				page(data.totalCount);					
			}
			
			/*leadID=data.leadID;*/
			//alert(111111111+leadID);							
		});
	}
    //成员列表回显
    function sysuserhtml_m(data){
    	//alert(data);
    	var html = "";    	
    	$.each(data,function(n,value) { 
    		//alert(value.sjob);    		
    		html += "<tr>" 
    		if(value.sdepartmentId==department_id){
    			html += '<td><img src="../sys/set/images/s_check_no.png" class="s_fk_pic1" _id="'+value.sid+'" _name="'+value.sname+'"/></td>'     			
    		}else{
    			html += '<td><img src="../sys/set/images/s_check.png" class="s_fk_pic1" _id="'+value.sid+'" _name="'+value.sname+'"/></td>'     			
    		}
    		html += "<td>"+value.sname+"</td>"
    		html += "<td>"+value.saccount+"</td>"
    		if(value.semail==null){
    			html += "<td>"+""+"</td>"
    		}else{
    			html += "<td>"+value.semail+"</td>"
    		} 
    		if(value.sjob==null){
    			html += "<td>"+""+"</td>"
    		}else{
    			html += "<td>"+value.sjob+"</td>"
    		} 
    		if(value.roles==null){
    			html += "<td>"+""+"</td>"
    		}else{
    			html += "<td>"+value.roles+"</td>"
    		} 

    		html += "</tr>"

    	});    	
    	$("#userList").html(html)    	
    }
    
    //部门主管列表回显查询
    function sysuserhtml_l(data){
    	//alert(data);
    	var html = "";    	
    	$.each(data,function(n,value) { 
    		//alert(value.sjob);    		
    		html += "<tr>" 
    		if(value.sid==leadID){
    			html += '<td><img src="../sys/set/images/s_check_no.png" class="s_fk_pic1" _id="'+value.sid+'" _name="'+value.sname+'"/></td>'     			
    		}else{
    			html += '<td><img src="../sys/set/images/s_check.png" class="s_fk_pic1" _id="'+value.sid+'" _name="'+value.sname+'"/></td>'     			
    		}
    		html += "<td>"+value.sname+"</td>"
    		html += "<td>"+value.saccount+"</td>"
    		if(value.semail==null){
    			html += "<td>"+""+"</td>"
    		}else{
    			html += "<td>"+value.semail+"</td>"
    		} 
    		if(value.sjob==null){
    			html += "<td>"+""+"</td>"
    		}else{
    			html += "<td>"+value.sjob+"</td>"
    		} 
    		if(value.roles==null){
    			html += "<td>"+""+"</td>"
    		}else{
    			html += "<td>"+value.roles+"</td>"
    		} 

    		html += "</tr>"

    	});    	
    	$("#userList").html(html)    	
    }
    /*<!-- //-----------------------------------页面加载完成------------------------------------- -->  */    
    $(function(){
    	$(".m_xpages select").change(function(){
    		pageSize = Number($(this).val());
    		currentPage = 1;
    		startIndex = 0;
    		sysuserList();
    	});
    	
    	$(".m_xpages a.prev").click(function(){
    		if(currentPage > 1){
    			currentPage--;
    			startIndex -= pageSize;
    			sysuserList();
    		}
    	});
    	
    	$(".m_xpages a.next").click(function(){
    		if(currentPage < pageCount){
    			currentPage++;
    			startIndex += pageSize;
    			sysuserList();
    		}
    	});
    	
    	$(".m_xpages :text").keyup(function(e){
    		if(e.keyCode==13){
    			var pageGo = $(this).val();
    			if(/^[0-9]+$/.test(pageGo)){
    				pageGo = Number(pageGo);
    				if(pageGo<1 || pageGo>pageCount){
    					alert('请输入合法页数');
    				}else if(pageGo != currentPage){
    					startIndex = (pageGo-1) * pageSize;
    					sysuserList();
    				}
    			}else{
    				alert('请输入合法页数');
    			}
    		}
    	});
    });
    function page(totalCount){
    	pageCount = totalCount/pageSize;
    	if (totalCount % pageSize > 0)
    		pageCount++;
    	pageCount = parseInt(pageCount);
    	
    	currentPage =  startIndex / pageSize + 1;
    	currentPage = parseInt(currentPage);
    	
    	if(currentPage == 1){
    		$(".prev").addClass("pageDisable");
    	}else{
    		$(".prev").removeClass("pageDisable");
    	}
    	
    	if(currentPage == pageCount || pageCount == 0){
    		$(".next").addClass("pageDisable");
    	}else{
    		$(".next").removeClass("pageDisable");
    	}
    	
    	$(".m_xpages>.mian>span:eq(1)").text('共'+totalCount+'条');
    	$(".m_xpages>.mian>span:eq(2)").text(currentPage+'/'+pageCount+'页');
    }
    /* 页面显示功能结束 */
	//搜索的点击事件
    $(function(){
     	$('#searchA').click(function(){
     	    var startIndex = 0;
     	    var pageSize = 5;
     	    var currentPage = 1;
     	    var pageCount = 0;
     	    $(function(){
     	    	//alert($("#keyWord").text());
     	    	//alert($("#s").val());
     	    	sysuserList();
     	    });
     	})
    });    
    /* 复选框可选 */
  	$(document).on("click",".s_fk_pic1",function(){
//  		if(temp == 1){
//  			var src = $(this).attr('src');
//   	 		var on_length = $(".s_fk_pic1[src$='s_check_no.png']").length;
//   			if(on_length > 0){
//   				alert("主管只能添加一位");
//   				return ;
//   			}
//     		if(src.indexOf('s_check.png')>0){
//       			$(this).attr('src', '../sys/set/images/s_check_no.png');
//     		}else{
//      		 	$(this).attr('src', '../sys/set/images/s_check.png');
//     		} 
//  		}else if(temp == 2){
  			var src = $(this).attr('src');
  	     	if(src.indexOf('s_check.png')>0){
  	       		$(this).attr('src', '../sys/set/images/s_check_no.png');
  	     	}else{
 	      		 $(this).attr('src', '../sys/set/images/s_check.png');
  	     	}
  		//}
  	});  
  	var store_names=new Array();
    var store_ids=new Array();
    var userId="";
    var userName="";
	  /* 列表查询的确定按钮 */	
	$('#s_confirms').click(function(){
		if(temp == 1){
			//alert("点击确定");
			//取出userId
			var on_length = $(".s_fk_pic1[src$='s_check_no.png']").length;
			console.log("on_length"+on_length);
			if(on_length > 1){
				alert("主管只能添加一位");
				return ;
			}
		   	userId = $(".s_fk_pic1[src$='s_check_no.png']").attr("_id"); 
			//取出userName
			userName = $(".s_fk_pic1[src$='s_check_no.png']").attr("_name"); 
			if(userId==null||userId==""){
				$('#de_manager_name_edit').html("");
			}
			var html='<li id="store_line_l"  class="delete_md_detail" cid="'+userName+'" >'+userName+'<img  mid="'+userName+'" id="delete_store_l" src="../sys/set/images/close.png" class="x_lista"></li>';
			$('#de_manager_name_edit').html(html);
			//$('#de_manager_name_edit').attr("userId",userId);
			//$('#de_manager_name_edit').attr("userName",userName);
	        $('.s_popups').hide();
	        $('.s_number_list').hide();
			//var html= '<li id="store_line'+i+'" indexNum="'+i+'" class="delete_md_detail" cid="'+store_names[i]+'" >'+store_names[i]+'<img indexNum="'+i+'" mid="'+store_names[i]+'" id="delete_store" src="../sys/set/images/close.png" class="x_lista"></li>';
			//$('#de_manager_name_edit').html(html);
			$('#de_manager_name_edit').val(userName).attr("readonly",true);
	        $('.s_popup').show();
	        $('.issue').show();
			    //alert(userId);
		}else if(temp == 2){
				//取出userId
//				var userId = "";
//				$(".s_fk_pic1[src$='s_check_no.png']").each(function(){
//		   			userId += $(this).attr("_id")+",";
//				}); 
				//alert("点击确定"+userId);
				//取出userName
//				var userName = "";
//				$(".s_fk_pic1[src$='s_check_no.png']").each(function(){
//				    userName += $(this).attr("_name")+";";
//			 	}); 
				store_names.length=0;
				store_ids.length=0;
				$(".s_fk_pic1[src$='s_check_no.png']").each(
    				function(i, d) {
    					var name = $(this).attr("_name");
    					var id=$(this).attr("_id");
    					store_names[i]=name;
    					store_ids[i]=id;
    			});
				var html='';
				for(var i in store_names){
					html += '<li id="store_line'+i+'" indexNum="'+i+'" class="delete_md_detail" cid="'+store_names[i]+'" >'+store_names[i]+'<img indexNum="'+i+'" mid="'+store_names[i]+'" id="delete_store" src="../sys/set/images/close.png" class="x_lista"></li>';
				}
				$('#de_member_edit').html(html);
	 			//$('#de_member_edit').attr("userId",userId);
	 			//$('#de_member_edit').attr("userName",userName);
	 			//$('#de_member_edit').text(userName);
	 			//alert(userId);
	            $('.s_popups').hide();
	            $('.s_number_list').hide();
	    		//$('#de_member_edit').val(userName).attr("readonly",true);
	            $('.s_popup').show();
	            $('.issue').show();
		}
	});  
	/*   成员变更，即添加主管和 成员的完成按钮 */
	var w_word=$('#warning_word_bj');
	$(function(){
		//$('#s_confirm_add').click(function(){
		$(document).on('click','#s_confirm_add',function(){
			console.log("进入完成的点击事件");
			//添加成员按钮获取部门id
			var department_id=$('.fL_add').attr('department_id');
			//var leader_id=$('#de_manager_name_edit').attr('userId');
			//alert(leader_id);
			var leader_id=userId;
			console.log("leader_id"+leader_id);
			//alert(leader_id);
			var storeIds=store_ids.join(",");
			//var sysuserId=$('#de_member_edit').attr('userId');
			if(storeIds!=""){
				storeIds=storeIds+",";
			}
			//alert(storeIds);
			var url = path+"/api/department/addMembers";
	      	var params = {"department_id" : department_id,"leader_id" : leader_id,"sysuserId" : storeIds};		
	      	$.ajax({    type: "POST",
	               		 url: path+"/api/department/addMembers",
	               		 data:  {"department_id" : department_id,"leader_id" : leader_id,"sysuserId" : storeIds},
	         			dataType: "json",
	         			success: function(data){
	         				if("1"==data.error_code){         					
	                  			//alert("添加成功");
	         					//location.reload();
	                  		    $('.s_popup').hide();
	                            $('.issue').hide();
	         				}else{
	         					//alert("添加失败"); 
	         					//location.reload();
	         					w_word.text(data.error_msg);
	         					$('.s_popup').hide();
	                            $('.issue').hide();
	         				}
	         			}
	      	}); 
		});
	 });
/*	$(function(){
		$.post(path+'/api/account/getRoles', function(data) {	
		    $.each($.parseJSON(data.obj),function(i,d){
			    var str = "";
			    str += '<li>';
			    str += d.name;
			    str += '</li>';
			    $("#ro_s").append(str);
		    })
	    }); 
	});*/
	//-查询列表显示取出部门名字集合------------ -->
	$(function(){
		$.post(path+'/api/account/getDepartments', function(data) {
		    $.each($.parseJSON(data.obj),function(i,d){
			    var str = "";
			    str += '<li>'+d.name+'</li>';
			    $("#department_name").append(str);
		    })
	    }); 
	});
	//打岔移除成员
	  $(document).on('click','#delete_store',function(){
      	var index=$(this).attr("indexNum");
      	var lineId="#store_line"+$(this).attr("indexNum");
      	$(lineId).remove();
      	
      	console.log("删除的下标---->"+index);
      	store_ids.splice(index,1);
      }); 
	  
		//打岔移除主管
	  $(document).on('click','#delete_store_l',function(){
      	$("#store_line_l").remove();
      	userId=""
      }); 